package com.magictower.primary.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;

import com.magictower.primary.R;
import com.magictower.primary.common.SPConstant;
import com.magictower.primary.utils.SIMUtils;
import com.magictower.primary.view.ItemView;

/**
 * Created by kejunzhan on 2017/12/7.
 */

public class Setup2Activity extends BaseSetupActivity {

    private ItemView sivSim;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setup2);

        sivSim = (ItemView) findViewById(R.id.siv_sim);
        String sim = mPref.getString(SPConstant.SIM, "");
        if (!TextUtils.isEmpty(sim)) {
            //开启
            sivSim.setCheck(true);
        } else {
            //关闭
            sivSim.setCheck(false);
        }
        sivSim.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (sivSim.isCheck()) {
                    //更新显示
                    sivSim.setCheck(false);
                    mPref.edit().remove(SPConstant.SIM).apply();
                } else {
                    //更新显示
                    sivSim.setCheck(true);
                    //更新share preference
                    String simNum = SIMUtils.getSimIccId(Setup2Activity.this);
                    mPref.edit().putString(SPConstant.SIM, simNum).apply();
                }
            }
        });

    }

    @Override
    public void showNextPage() {
        String sim = mPref.getString(SPConstant.SIM, "");
        if (!TextUtils.isEmpty(sim)) {
            //开启
            startActivity(new Intent(Setup2Activity.this, Setup3Activity.class));
            finish();
            overridePendingTransition(R.anim.page_alpha_in, R.anim.page_tran_out);
        }
    }

    @Override
    public void showPreviousPage() {
        startActivity(new Intent(Setup2Activity.this, Setup1Activity.class));
        finish();
        overridePendingTransition(R.anim.page_tran_in, R.anim.page_alpha_out);
    }

}
